package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.DeleteMapping;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    @Select("select * from address_book where user_id=#{userId}")
    List<AddressBook> list(Long userId);
    @Select("select * from address_book where id=#{id}")
    AddressBook getById(Long id);

    @Select("select * from address_book where is_default=1 and user_id=#{userId}")
    AddressBook getDefault(Long userId);
    @Insert("insert into address_book (user_id,consignee,sex,phone,province_code,province_name,city_code,city_name,district_code,district_name,detail,label,is_default)" +
            "values (#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName},#{cityCode},#{cityName},#{districtCode},#{districtName},#{detail},#{label},#{isDefault})")
    void save(AddressBook addressBook);
    @Update("update address_book set is_default=#{status} where id=#{id} and user_id=#{userId}")
    void setDefault(Long id,Long userId,Integer status);

    void update(AddressBook addressBook);

    @Delete("delete from address_book where id=#{id} and user_id=#{currentId}")
    void delete(Long id, Long currentId);
}
